﻿#include "dwgpoint.h"

DwgPoint::DwgPoint(QObject *parent)
    : DwgObject{parent}
{

}


void DwgPoint::Draw(QPainter *painter)
{
    if (mDeleteed) return;

    if (mSelected)
    {
        painter->setPen(Qt::red);
    }
    else
    {
        painter->setPen(Qt::black);
    }

    // 绘制一个小圆点
    painter->drawEllipse(mpt, 2, 2);
}

void DwgPoint::SetData(QPointF p1, QPointF p2)
{
    mpt = p1;
}
void DwgPoint::Select(QPointF pt)
{
    qreal distance = QLineF(mpt, pt).length();

    // 如果距离小于某个阈值（例如 5），则认为选中了点
    if (distance < 5)
    {
        mSelected = true;

    }
    else
    {
        mSelected = false;

    }
}
